/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.opgea.crm.domain.entities;

import java.io.Serializable;
import java.util.Collection;
import java.util.Date;
import java.util.List;

import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

import com.opgea.crm.domain.entities.security.CrmUser;

/**
 *
 * @author Admin
 */
@Entity
@Table(name = "employee")
public class Employee implements Serializable{

    /**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	@Id
    @GeneratedValue
    @Column(name = "id", nullable = false)
    private Long id;
    @Column(name = "prefix", length = 45)
    private String prefix;
    @Column(name = "firstName", length = 45)
    private String firstName;
    @Column(name = "middleInitial", length = 45)
    private String middleInitial;
    @Column(name = "lastName", length = 45)
    private String lastName;
    @Column(name = "suffix", length = 45)
    private String suffix;
    @Column(name = "title", length = 45)
    private String title;
    @Basic(optional = false)
    @Column(name = "emp_code", nullable = false, length = 45)
    private String empCode;
    @Column(name = "employeeType")
    private int employeeType;
    @ManyToOne
    @JoinColumn(name = "company_id", referencedColumnName = "id")
    private Company company;

    
    
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "employee")
    private Collection<Employeephones> employeephonesCollection;
    
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "employee")
    private Collection<Employeeemails> employeeemailsCollection;    
    
    /*
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "employee")
    private Collection<Leadprofile> leadprofileCollection;
    
    @OneToMany(mappedBy = "salesPerson")
    private Collection<Opportunity> opportunitiesOfSalesPerson;
    
    @OneToMany(mappedBy = "assignTo")
    private Collection<Activity> activitiesOfAssignedPerson; 
    
    @OneToMany(cascade={CascadeType.PERSIST,CascadeType.MERGE}, mappedBy="createdBy",fetch=FetchType.EAGER)
	private List<ProjectDetails> projects;
    */
    @ManyToMany(mappedBy="members")
    private List<ProjectDetails> workingInProjects;
	
    
    @OneToOne(cascade =  CascadeType.ALL, mappedBy="employee")
    private CrmUser user;
    
	@ManyToOne(cascade=CascadeType.REFRESH)
	@JoinColumn(name="createdBy", referencedColumnName="username")
	private CrmUser createdBy;
	
	@Temporal(TemporalType.TIMESTAMP)
	@Column(name="createdat")
	private Date createdAt;
    
  
	public Employee() {
    	//workingInProjects = new ArrayList<ProjectDetails>();
    }
	
	public Employee(Long assignedToId, String firstName, String middleInitial, String lastName){
		this.id = assignedToId;
		this.firstName = firstName;
		this.middleInitial = middleInitial;
		this.lastName = lastName;
	}

    public List<ProjectDetails> getWorkingInProjects() {
		return workingInProjects;
	}

	public void setWorkingInProjects(List<ProjectDetails> workingInProjects) {
		this.workingInProjects = workingInProjects;
	}

	public Employee(Long id) {
        this.id = id;
    }

    public Employee(Long id, String empCode) {
        this.id = id;
        this.empCode = empCode;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getPrefix() {
        return prefix;
    }

    public void setPrefix(String prefix) {
        this.prefix = prefix;
    }

    public String getFirstName() {
        return firstName;
    }

    public void setFirstName(String firstName) {
        this.firstName = firstName;
    }

    public String getMiddleInitial() {
        return middleInitial;
    }

    public void setMiddleInitial(String middleInitial) {
        this.middleInitial = middleInitial;
    }

    public String getLastName() {
        return lastName;
    }

    public void setLastName(String lastName) {
        this.lastName = lastName;
    }

    public String getSuffix() {
        return suffix;
    }

    public void setSuffix(String suffix) {
        this.suffix = suffix;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getEmpCode() {
        return empCode;
    }

    public void setEmpCode(String empCode) {
        this.empCode = empCode;
    }

	public int getEmployeeType() {
		return employeeType;
	}

	public void setEmployeeType(int employeeType) {
		this.employeeType = employeeType;
	}

	public Company getCompany() {
		return company;
	}

	public void setCompany(Company company) {
		this.company = company;
	}

	public void setEmployeephonesCollection(Collection<Employeephones> employeephonesCollection) {
		this.employeephonesCollection = employeephonesCollection;
	}

	public Collection<Employeephones> getEmployeephonesCollection() {
		return employeephonesCollection;
	}

	public void setEmployeeemailsCollection(Collection<Employeeemails> employeeemailsCollection) {
		this.employeeemailsCollection = employeeemailsCollection;
	}

	public Collection<Employeeemails> getEmployeeemailsCollection() {
		return employeeemailsCollection;
	}

	public void setUser(CrmUser user) {
		this.user = user;
	}

	public CrmUser getUser() {
		return user;
	}

	public void setCreatedBy(CrmUser createdBy) {
		this.createdBy = createdBy;
	}

	public CrmUser getCreatedBy() {
		return createdBy;
	}

	public void setCreatedAt(Date createdAt) {
		this.createdAt = createdAt;
	}

	public Date getCreatedAt() {
		return createdAt;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((id == null) ? 0 : id.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Employee other = (Employee) obj;
		if (id == null) {
			if (other.id != null)
				return false;
		} else if (!id.equals(other.id))
			return false;
		return true;
	}

	@Override
	public String toString() {
		return "Employee [id=" + id + ", prefix=" + prefix + ", firstName="
				+ firstName + ", middleInitial=" + middleInitial
				+ ", lastName=" + lastName + ", suffix=" + suffix + ", title="
				+ title + ", empCode=" + empCode + ", employeeType="
				+ employeeType + ", company=" + company + "]";
	}
    
    
}
